﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Kiosk
{
    public partial class Form1 : Form
    {
        private SourceBar sourceBar = new SourceBar();
        private BrowseBar browseBar = new BrowseBar();
        private WelcomeScreen welcomeScreen = new WelcomeScreen();
        private Timer timer = new Timer();
        private Control currentView;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            timer.Start();
            timer.Interval = 500;
            timer.Tick += new EventHandler(timer_Tick);

            addSourceBar();
            addBrowseBar();

            welcomeScreen.IndustryClick += new EventHandler(welcomeScreen_IndustryClick);
            switchToScreen(welcomeScreen, "BÖLÜM SEÇİMİ");
        }

        void timer_Tick(object sender, EventArgs e)
        {
            statusBar1.Invalidate();
        }

        public bool IsSourceBarActive
        {
            get { return sourceBar.Enabled && sourceBar.Visible; }
            set { sourceBar.Enabled = sourceBar.Visible = value; }
        }

        public bool IsBrowseBarActive
        {
            get { return browseBar.Enabled && browseBar.Visible; }
            set { browseBar.Enabled = browseBar.Visible = value; }
        }

        private void toggleSourceBar()
        {
            IsSourceBarActive = !IsSourceBarActive;
        }

        private void toggleBrowseBar()
        {
            IsBrowseBarActive = !IsBrowseBarActive;
        }

        private void footerBar1_SourceClick(object sender, EventArgs e)
        {
            IsBrowseBarActive = false;
            toggleSourceBar();
        }

        private void footerBar1_AnaClick(object sender, EventArgs e)
        {
            IsSourceBarActive = false;
            toggleBrowseBar();
        }

        private void switchToScreen(Control control, string title)
        {
            if (currentView != null)
                panelMain.Controls.Remove(currentView);

            IsSourceBarActive = false;
            IsBrowseBarActive = false;

            control.Location = new Point(0, 0);

            panelMain.Controls.Add(control);

            currentView = control;

            statusBar1.Title = title;
        }

        #region Adding Bars

        private void addSourceBar()
        {
            sourceBar.Location = new Point(sourceBar.Width / 3, panelMain.Height - sourceBar.Height);

            panelMain.Controls.Add(sourceBar);
            
            sourceBar.BringToFront();

            IsSourceBarActive = false;
        }

        private void addBrowseBar()
        {
            browseBar.Location = new Point(0, panelMain.Height - browseBar.Height);
            browseBar.Button1Click += new EventHandler(browseBar_Button1Click);
            browseBar.Button2Click += new EventHandler(browseBar_Button2Click);
            browseBar.Button3Click += new EventHandler(browseBar_Button3Click);
            browseBar.Button4Click += new EventHandler(browseBar_Button4Click);

            panelMain.Controls.Add(browseBar);

            browseBar.BringToFront();

            IsBrowseBarActive = false;
        }

        #endregion

        #region View Add Methods

        void addFirstView()
        {
            FirstView firstView = new FirstView();

            firstView.RightNavigation += new EventHandler(firstView_FirstViewRightClick);
            firstView.SolutionNavigation += new EventHandler(firstView_SolutionNavigation);

            switchToScreen(firstView, "BÖLÜM I: KOMBİNATORİK ANALİZ");
        }

        void addSecondView()
        {
            SecondView secondView = new SecondView();

            secondView.RightNavigation += new EventHandler(secondView_RightNavigation);
            secondView.LeftNavigation += new EventHandler(secondView_LeftNavigation);

            switchToScreen(secondView, "BÖLÜM I: KOMBİNATORİK ANALİZ");
        }

        void addSolutionView()
        {
            FinalSolutionView finalSolutionView = new FinalSolutionView();

            finalSolutionView.LeftNavigation += new EventHandler(finalSolutionView_LeftNavigation);

            switchToScreen(finalSolutionView, "BÖLÜM I: KOMBİNATORİK ANALİZ");
        }

        void addIndustryView()
        {
            IndustryScreen industryScreen = IndustryScreen.Instance;

            industryScreen.FirstChapterClick += new EventHandler(industryScreen_FirstChapterClick);

            switchToScreen(industryScreen, "ENDÜSTRİ");
        }

        #endregion

        #region Navigation Methods

        void browseBar_Button1Click(object sender, EventArgs e)
        {
            switchToScreen(welcomeScreen, "BÖLÜM SEÇİMİ");
        }

        void browseBar_Button2Click(object sender, EventArgs e)
        {
            addFirstView();
        }

        void browseBar_Button3Click(object sender, EventArgs e)
        {
            addSecondView();
        }

        void browseBar_Button4Click(object sender, EventArgs e)
        {
            addSolutionView();
        }

        void industryScreen_FirstChapterClick(object sender, EventArgs e)
        {
            addFirstView();
        }

        void firstView_SolutionNavigation(object sender, EventArgs e)
        {
            addSolutionView();
        }

        void finalSolutionView_LeftNavigation(object sender, EventArgs e)
        {
            addSecondView();
        }

        void firstView_FirstViewRightClick(object sender, EventArgs e)
        {
            addSecondView();
        }

        void secondView_RightNavigation(object sender, EventArgs e)
        {
            addSolutionView();
        }

        void secondView_LeftNavigation(object sender, EventArgs e)
        {
            addFirstView();
        }

        void welcomeScreen_IndustryClick(object sender, EventArgs e)
        {
            addIndustryView();
        }

        #endregion
    }
}
